<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=<device-width>, initial-scale=1.0">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap-grid.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js
    "></script>
    <title>Document</title>
</head>
<body>
    <div class="container">
        <h2 class="page-header">基本使用</h2>
        <button class="btn btn-primary">发送GET请求</button>
        <button class="btn btn-primary">发送POST请求</button>
        <button class="btn btn-primary">发送PUT请求</button>
        <button class="btn btn-primary">发送DELETE请求</button>
    </div>
    <script>
        //获取按钮
        const btns=document.querySelectorAll('button');
        //axios
        btns[0].onclick=function(){
            //默认配置
            axios.defaults.method = 'GET';//设置默认的请求类型为GET
            axios.defaults.baseURL = 'http://localhost:3000';//设置默认的请求类型为GET
            axios.defaults.params = {id:100};
             axios.defaults.timeout=3000;//默认 如果请求时间超过`timeout`，请求将被中止
           console.log(axios);
            axios({
                url:'/posts'
            }).then(response=>{
                console.log(response)
            });
        }
    </script>
</body>
</html>